# coding=utf-8
"""
Author: Mr.夏末
@Function: 字符串处理
"""
s = 'will,tufei,zhangxin,roy'
# 得到每一个老师的名字
# 切割：沿着某个特殊字符串，把源字符串切割为数个小份
names = s.split(',')
print(names)
# 把所有老师名字用逗号组合起来
# 组合
print(','.join(names))

# 边界值
s = 'will'
names = s.split(',')
print(names)
print(','.join(names))

# 替换
s = 'will, tufei, zhangxin, roy, will, tufei, zhangxin, roy,will, tufei, zhangxin, roy, will, tufei, zhangxin, roy,will, tufei, zhangxin, roy'
# will替换成卡卡
# 返回一个替换后的字符串
# old，new，count
# 需要替换的字符串，替换后的字符串，替换多少个，默认-1，替换全部
k = s.replace('will', 'kaka', -1)
print(k)

# 替换第二个will为卡卡
# 先把前两个替换为卡卡，再把前一个替换回去
k = s.replace('will', 'kaka', 2)
print(k)
k = k.replace('kaka', 'will', 1)
print(k)

print("----------------------------------------------------------------------------")
# 替换最后一个will为卡卡
s = 'will, tufei, zhangxin, roy, will, tufei, zhangxin, roy,will, tufei, zhangxin, roy, will, tufei, zhangxin, roy,will, tufei, zhangxin, roy, will, roy'
s = s[::-1].replace("lliw", "akak", 1)[::-1]
print(s)

# 替换第n个will为卡卡:；例如第3个:n ,n-1
s = 'will, tufei, zhangxin, roy, will, tufei, zhangxin, roy,will, tufei, zhangxin, roy, will, tufei, zhangxin, roy,will, tufei, zhangxin, roy, will, roy'
s = s.replace("will", "kaka", 3).replace("kaka", "will", 2)
print(s)
